(function($){

    $.fn.shuffle = function() {

        var allElems = this.get(),
            getRandom = function(max) {
                return Math.floor(Math.random() * max);
            },
            shuffled = $.map(allElems, function(){
                var random = getRandom(allElems.length),
                    randEl = $(allElems[random]).clone(true)[0];
                allElems.splice(random, 1);
                return randEl;
           });

        this.each(function(i){
            $(this).replaceWith($(shuffled[i]));
        });

        return $(shuffled);

    };
})(jQuery);

$(document).ready(function(){
	$('table.startups tr').shuffle();
	$('table.startups tr.headstartups').prependTo($('table.startups'));
});

/** Menu */

var open = function(id) {
  $('.menuitem').removeClass('menuselected');
  $('#menu' + id + '-menu').addClass('menuselected');
  
  $('.page').removeClass('pageselected');
  $('#menu' + id + '-page').addClass('pageselected');
};


$('#menu1-menu').live('click', function(evt) { open(1); });
$('#menu2-menu').live('click', function(evt) { open(2); });
$('#menu3-menu').live('click', function(evt) { open(3); });
$('#menu4-menu').live('click', function(evt) { open(4); });
$('#menu5-menu').live('click', function(evt) { open(5); });
$('#menu6-menu').live('click', function(evt) { open(6); });
$('#menu7-menu').live('click', function(evt) { open(7); });
$('#writeus').live('click', function(evt) { open(7); });
$('.pitchgetmore').live('click', function(evt) { 
	$(this.parentNode).find('.pitchmore').toggle();
	$(this).text($(this).text() === "Fermer" ? "Lire la suite..." : "Fermer");
});

$(function() {
    $("#add-dialog").dialog({ autoOpen: false, width: 600, height: 960 });
});

$(function() {
    $("#feedback-dialog").dialog({ autoOpen: false, width: 600, height: 700 });
});

$('#add').live('click', function() {
		 $("#add-dialog").dialog('open');
	       });

$('#register-your-startup').live('click', function() {
		 $("#add-dialog").dialog('open');
	       });
$('#feedback').live('click', function() {
		 $("#feedback-dialog").dialog('open');
	       });

$('#adhesion').live('click', function() {
		      open(5);
});


